from gradio_client import Client, file
import requests
import os


class aniPortraitServer:
    def __init__(self):
        self.gradio_host = "http://192.168.31.212"
        self.gradio_port = 8100
        self.gradio_web = 8000
        # self.client = Client(
        #     f"{self.gradio_host}:{self.gradio_port}/", ssl_verify=False
        # )

    def stop(self):
        # self.client.close()
        pass

    def listModels(self):
        try:
            r = requests.get(f"{self.gradio_host}:{self.gradio_web}/api/mod/")
            res = r.json() if r and r.status_code == 200 else None
        except BaseException as err:
            res = None
        return res

    # def postVideo(self, **kwsrgs):
    #     try:
    #         result = self.client.predict(
    #             acc_flag=True, api_name="/audio2video", **kwsrgs
    #         )
    #     except BaseException as err:
    #         return None
    #     else:
    #         return result

    def postVideo2(self, **kwsrgs):
        data = kwsrgs
        try:
            r = requests.post(
                f"{self.gradio_host}:{self.gradio_web}/api/video/", data=data
            )
            res = r.json() if r and r.status_code == 200 else None
        except BaseException as err:
            res = None
        return res
